#include <stdio.h>
#define N 10
struct actor
{
    // 长度要加1，串的最后有'\0'标识
    char numb[4];
    char name[21];
    int score;
};

int main()
{
    struct actor a[N];
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%s %s %d", a[i].numb, a[i].name, &a[i].score);
    int count = 0;
    for (i = 0; i < n; i++)
    {
        if (a[i].score >= 90)
        {
            a[i].score = 'S';
            count++;
        }
        else if (a[i].score >= 80 && a[i].score <= 89)
        {
            a[i].score = 'A';
        }
        else if (a[i].score >= 70 && a[i].score <= 79)
        {
            a[i].score = 'B';
        }
        else
        {
            a[i].score = 'C';
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("%s %s %c\n", a[i].numb, a[i].name, a[i].score);
    }

    printf("%d", count);
    return 0;
}
